package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.business.dao.inter.DonationAssignmentItemDao;
import com.yunfeisoft.business.model.DonationAssignmentItem;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * ClassName: DonationAssignmentItemDaoImpl
 * Description: 捐赠物品分配详细Dao实现
 * Author: Jackie liu
 * Date: 2020-05-14
 */
@Repository
public class DonationAssignmentItemDaoImpl extends BaseDaoImpl<DonationAssignmentItem, String> implements DonationAssignmentItemDao {

    @Override
    public Page<DonationAssignmentItem> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    @Override
    public List<DonationAssignmentItem> queryByDonationAssignmentId(String donationAssignmentId) {
        if (StringUtils.isBlank(donationAssignmentId)) {
            return new ArrayList<>();
        }

        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("donationAssignmentId", donationAssignmentId);
        return query(wb);
    }

    @Override
    public int deleteByDonationAssignmentId(String donationAssignmentId) {
        String sql = String.format("DELETE FROM %s WHERE DONATION_ASSIGNMENT_ID_ = ?", domainModel.getTableName());
        return jdbcTemplate.update(sql, donationAssignmentId);
    }
}